<template>
  <div>
    <el-form ref="form" :model="skyDetails" label-width="80px">
      <el-form-item label="数据类别">
        <el-input v-model="skyDetails.type"></el-input>
      </el-form-item>
      <el-form-item label="数据名称">
        <el-input v-model="skyDetails.dataCode"></el-input>
      </el-form-item>
      <el-form-item label="服务接口">
        <el-input v-model="skyDetails.interfaceId"></el-input>
      </el-form-item>
      <el-divider>接口参数</el-divider>
      <el-form-item label="要素名称">
        <el-row>
          <el-input v-model="skyDetails.inputElements" style="    width: 1600px;margin-right: 14px;"></el-input>
          <el-button type="primary" @click="eleButtonClick" v-show="!tableShow">选择要素</el-button>
          <el-button type="primary" @click="submitElements" v-show="tableShow">确定</el-button>
        </el-row>
        <el-table ref="multipleTable" v-show="tableShow" :data="elements" tooltip-effect="dark" style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column prop="elementName" label="要素名称" width="120">
          </el-table-column>
          <el-table-column prop="elementCode" label="要素代码" show-overflow-tooltip>
          </el-table-column>
        </el-table>
      </el-form-item>
      <div v-for="(item, index) in skyDetails.skyParameters" :key="item.id">
        <el-form-item :label="item.parameterName">
          <!-- 注意这里我们使用了 item.name 而不是 form.name -->
          <el-input v-model="skyDetails.skyParameters[index].value"></el-input>
        </el-form-item>
      </div>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getSkyEngineDetails, getDownloadFile } from '@/api/SkyEngine'
export default {
  name: "SkyEngineDetails",
  data() {
    return {
      skyDetails: {},
      region: '',
      tableShow: false,
      multipleSelection: [],
      elements: [],
      eleButShow: true
    }
  },
  created() {
    const id = this.$route.query.id;
    console.log(id); // 输出传递过来的 id 值
    this.getSkyDetails(id);
  },
  methods: {
    /**
     * 获取天擎详情
     */
    getSkyDetails(id) {
      getSkyEngineDetails(id).then(res => {
        this.skyDetails = res.responseData.data;
        this.elements = res.responseData.data.elements;
      })
        .catch(res => {
          console.log(res);
          // 可以在这里处理错误，比如显示错误消息
        })
    },
    /**
     * 下载文件信息
     */
    getDownloadFile(data) {
      getDownloadFile(data).then(res => {
        console.log(res);
      })
        .catch(res => {
          console.log(res);
          // 可以在这里处理错误，比如显示错误消息
        })
    },
    /**
     * 表单点击事件
     */
    onSubmit() {
      console.log('submit!');
      console.log(this.skyDetails.skyParameters);
      console.log(this.skyDetails);
      this.getDownloadFile(this.skyDetails);
    },
    /**
     * 要素按钮点击事件
     */
    eleButtonClick() {
      this.tableShow = true;
    },
    /**
     * 要素选择
     * @param val 要素
     */
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /**
     * 要素提交确定事件
     */
    submitElements() {
      this.skyDetails.inputElements = '';
      this.tableShow = false;
      this.multipleSelection.forEach(e => {
        this.skyDetails.inputElements = this.skyDetails.inputElements + e.elementCode + ','
      })
      this.skyDetails.inputElements = this.skyDetails.inputElements.substring(0, this.skyDetails.inputElements.length - 1)
    }
  }
}
</script>



<style scoped></style>